package Machine;
import java.util.Timer;

import org.omg.CORBA.*;
import org.omg.PortableServer.POA;
import com.sun.org.apache.xml.internal.security.Init;
import  Monitoring_Machine.*;
import Machine.IO;

public class MachineCliente{
	
	public ORB orb;
	public POA poa;
	public String liste_Moniteurs[];
	public Operateur[] operateur;
	public Machine machine_locale; 
	
	public MachineCliente(ORB orb,POA poa,String[] liste_Moniteurs, Machine locale_machine)
	{
		
		this.orb = orb;
		this.poa=poa;
		this.liste_Moniteurs=liste_Moniteurs;
		machine_locale=locale_machine;
		
		int nb_monitors=liste_Moniteurs.length;
		
		String[] ref=new String[nb_monitors];
		org.omg.CORBA.Object[] obj=new org.omg.CORBA.Object[nb_monitors];
		operateur=new Operateur[nb_monitors];
		
        for (int i = 0; i < liste_Moniteurs.length; i++) {
		ref[i] = IO.readIOR(liste_Moniteurs[i]);
	    obj[i] = orb.string_to_object(ref[i]);
	    operateur[i] = OperateurHelper.narrow(obj[i]);
        }
	
        // Alerter tous les monitors enregistrer
		checkForAlert();
		
	}
	
	public void checkForAlert()
	{
		Type_commande[] cmds = new Type_commande[2];
		cmds[0]=Type_commande.cpu;
		cmds[1]=Type_commande.mem;
		Timer timer = new Timer();
		Alerte alerteTask = new Alerte(cmds,machine_locale, operateur);
		timer.schedule(alerteTask, 5000000);
	}
	


	
    
}
